In [1]:
import param
import pandas as pd 
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import panel as pn
pn.extension()

import plotly.express as px

# make plots static
%matplotlib inline

x_data = 6*np.random.random(50)
y_data = np.sin(x_data)

# create a simple dataframe of animal ratings
# df = pd.DataFrame({'Animal':['Pig', 'Goat' ,'Sheep', 'Frog', 'Goat', 'Goat', 'Pig', 'Sheep', 
#                              'Octopus', 'Goat', 'Pig', 'Sheep', 'Octopus', 'Frog', 'Goat', 'Goat',
#                             'Pig', 'Pig', 'Sheep', 'Frog', 'Frog', 'Octopus', 'Octopus'], 
#                    'Rating':[3, 10, 3, 2, 9, 10, 4, 1, 
#                              1, 8, 5, 6, 2, 4, 10, 9,
#                             5, 5, 3, 2, 3, 1, 1]})
# df.to_csv('animals.csv')
# df = pd.read_csv('animals.csv')

url = 'https://raw.githubusercontent.com/aimalz/plasticc-explorer/master/animals.csv'
df = pd.read_csv(url)

# create a class containing an animal selector drop-down, various plots, and a data table output
class RatingsDashboard(param.Parameterized):
    
    # drop down selector widget containing the list of animals, with the default being 'Goat'
    Animal = param.ObjectSelector(default='Goat', objects=list(df.Animal.unique()))
    
    # create data set containing only the data applicable to the animal in the drop down selector
    def get_data(self):
        class_df = df[(df.Animal==self.Animal)].copy()
        return class_df
    
    # seaborn box plot for the chosen animal
    def box_view(self):
        data = self.get_data() 
        ax = sns.boxplot(data['Rating'])
        plt.close()
        return ax.figure
    
    # table of data for the chosen animal
    def table_view(self):
        data = self.get_data()
        return data
    
    # table of data for the chosen animal
    def plot_view(self):
        data = self.get_data()
        fig = px.scatter(x=x_data, y=y_data)
        #fig.show()
        return fig.show()

# create an instance of the class
rd = RatingsDashboard(name='')

# create a title for the dashboard
dashboard_title = '# Animal Ratings Dashboard'

# create some text describing the dashboard
dashboard_desc = 'An example of a simple interactive HoloViz Panel dashboard using a'\
                 ' dummy data set of animal ratings.'

# create a dashboard, defining the layout as one column containing the
# dashboard title, dashboard description, 'Animal' drop down selector,
# box plot, and data table
dashboard = pn.Column(dashboard_title, 
                      dashboard_desc,   
                      rd.param,       # 'Animal' drop down selector
                      rd.box_view,    # box plot
                      rd.table_view,   # data table
                      rd.plot_view   # data plot
                     )
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning: Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  warnings.warn(
In [2]:
# show the dashboard with the data embedded 
# (for using in an html download of the notebook so that 
# no 'callback' is required from the browser to get the data)
dashboard.embed(max_opts = 2)
  0%|          | 0/5 [00:00<?, ?it/s]
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning:

Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.

 20%|██        | 1/5 [00:00<00:00,  8.94it/s]
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning:

Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.

 40%|████      | 2/5 [00:00<00:00,  8.79it/s]
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning:

Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.

 60%|██████    | 3/5 [00:00<00:00,  8.91it/s]
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning:

Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.

 80%|████████  | 4/5 [00:00<00:00,  8.73it/s]
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning:

Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.

                                             
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning:

Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.

In [ ]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
In [ ]:
%matplotlib inline

sns.set(font_scale=1.3, style="ticks")
In [ ]:
x_data = 6*np.random.random(50)
y_data = np.sin(x_data)
plt.plot(x_data, y_data, '.')
In [ ]:
import plotly.express as px
fig = px.scatter(x=x_data, y=y_data)
fig.show()